<?php
namespace app\index\controller;
class DBclass
{
    protected $link;
    protected $M;
    public function __construct()
    {
        $this->link = new \PDO('mysql:host=122.51.4.58;dbname=test;port=3339', 'root', '123456');
        $this->M = new \PDO('mysql:host=122.51.4.58;dbname=test;port=3340', 'root', '123456');
        $this->link->exec("set names utf8");
        
    }


    public function Add($arr)
    {
        $sql = "insert into xshou value(null,'{$arr['name']}', '{$arr['saveTime']}', '{$arr['descs']}' );";
        // var_dump($sql);die;
        return $this ->link->exec( $sql );
    }

    public function Show($page, $name)
    {
        $size = 6;
        $limit = ($page-1)*$size;
        if($name == '')
        {
            $sql = "select * from xshou limit $limit,$page";
        }else{
            $sql = 'select * from xshou like name "%$name%" limit $limit,$page';
        }
        
        

        return $this->M->query( $sql )->fetchAll(2);
    }


    public function del( $id )
    {
        
        $sql = "delete from xshou where $id =".$id;
        

        return $this->M ->query( $sql )->fetchAll(2);
    }

    public function getOne( $id )
  {
      $sql = "select * from xshou where id = $id";
      return $this ->M->query( $sql )->fetch( 2 );
  }

    public function update( $arr )
    {
        $sql = "update xshou set  name = '{$arr['name']}',saveTime ='{$arr['saveTime']}', descs = '{$arr['descs']}'";
        return $this->link ->exec( $sql );
    }





}
?>